import React from 'react'
import ReactDOM from 'react-dom'
import userUnit, { IUser } from './utils/memory_utils';
import userStore from './utils/storage_utils';
import Ctx from './redux/context';
import reducer, { initialState } from './redux/reducer';
import App from './App';

const user: IUser['user'] = userStore.readUser();
userUnit.isNotLogin = !user;
userUnit.user = user;

const Index: React.FC = () => {
    const [state, dispatch] = React.useReducer(reducer, initialState);
    return (
        <Ctx.Provider value={{ state, dispatch }}>
            <App isNotLogin={userUnit.isNotLogin} />
        </Ctx.Provider>
    );
};

ReactDOM.render(
    <React.StrictMode>
        <Index />
    </React.StrictMode>,
    document.getElementById('root')
);